﻿using AutoMapper;
using B.S.BasicData.Api.Read.Application.Command.User;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.User
{
    public class GetShengHandler : IRequestHandler<GetShengCommand, ApiResult<List<ShengDTO>>>
    {
        private readonly IBaseRepository<ShengModel> shengRepo;
        private readonly IMapper mapper;

        public GetShengHandler(IBaseRepository<ShengModel> shengRepo, IMapper mapper)
        {
            this.shengRepo = shengRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<ShengDTO>>> Handle(GetShengCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ShengDTO>> res = new ApiResult<List<ShengDTO>>();
            var sheng = shengRepo.GetAll();
            res.Data = mapper.Map<List<ShengDTO>>(sheng);
            res.Code = ApiEnum.Success;
            res.Msg = "显示省级信息成功";
            return Task.FromResult(res);
        }
    }
}
